home *** CD-ROM | disk | FTP | other *** search
- Path: isonews.bbn.hp.com!hpbblb!news
- From: Matthias Dittrich <matti>
- Newsgroups: comp.lang.c
- Subject: Re: Checking for Ilegal Input
- Date: 4 Mar 1996 09:15:40 GMT
- Organization: Hewlett-Packard Co.
- Message-ID: <4hecbs$qf2@hpbblb.bbn.hp.com>
- References: <313855C7.5E86@aol.com>
- NNTP-Posting-Host: trabant.bbn.hp.com
- Mime-Version: 1.0
- Content-Type: text/plain; charset=us-ascii
- Content-Transfer-Encoding: 7bit
- X-Mailer: Mozilla 1.1N (X11; I; HP-UX A.09.07 9000/712)
- X-URL: news:313855C7.5E86@aol.com
-
- gregace@aol.com wrote:
- >I have a program where you must enter a number between 0 and 15 and check for
- >illegal input such as a number not between 0 and 15 or if a character is
- >entered.
- >
- >I used the scanf("%d",&number) to read the input.
- >
- >I check the illegal input by
- >
- >while (number<0 or number>15)
- >{ Printf("Enter a again:");
- > scanf("%d",&number);
- >}
- >
- >This check works fine accept when the user enters a character such as the
- >letter f. Does anyone know how to check illegal input that is not a number?
- >
- Check the return value of scanf. It gives the number of successfully assigned
- input items or EOF. In case of entering characters it returns 0.
-
- Good luck,
- Matthias
-
-